﻿using System;
using MsgDefine;

namespace SocketClient
{
    class Program
    {
        static void Main(string[] args)
        {
            ReqHelloworld msg = new ReqHelloworld();
            msg.ReqString = "你好我是客户端";
            ServerFramework.Net.Tcp.TcpClient client = new ServerFramework.Net.Tcp.TcpClient();
            client.onClientClose += Client_onClientClose;
            client.onRecvMessage += Client_onRecvMessage;
            if(client.Connect("127.0.0.1",8080))
            {
                client.Send(msg.Pack());
            }
            else
            {
                Console.WriteLine("连接不上");
            }
            Console.ReadLine();
        }

        private static void Client_onRecvMessage(ServerFramework.Net.Msg.MsgPacket obj)
        {
            if((EMsgID)obj.msgId == EMsgID.MSGID_HELLOW_WORLD)
            {
                ResHelloworld msg = ServerFramework.Net.Msg.MsgPacket.PacketToObj<ResHelloworld>(obj);
                Console.WriteLine(msg.ResString);
            }
            else
            {
                Console.WriteLine("未知消息");
            }

        }

        private static void Client_onClientClose(string obj)
        {
            
        }
    }
}
